<template>
    <div class="flex flex-col flex-1 p-2">
        <div class="flex justify-between">
            <div class="flex-1"></div>
            <div>
                <!-- <el-button type="primary" @click="openDialog">新增</el-button> -->
            </div>
        </div>
        <CustomTable class="mt-2" :data="tableData" :total="tableTotal" v-model:page-size="pageSize" @pageSize="getList"
            v-model:currentPage="pageNum" @currentPage="getList">
            <el-table-column type="index" width="60" label="序号" />
            <el-table-column prop="movieName" label="电影名称" />
            <el-table-column prop="movieImg" label="电影海报">
                <template #default="{ row }">
                    <el-image style="width: 100px; height: 100px" :src="row.movieImg" fit="cover" />

                </template>
            </el-table-column>
            <el-table-column label="评论人">
                <template #default="{ row }">
                    <div class="flex items-center justify-center">
                        <el-image style="width: 30px; height: 30px; border-radius: 20px;" :src="row.headUrl"
                            fit="cover" />

                        <div class="ml-2">{{ row.name }}</div>
                    </div>

                </template>
            </el-table-column>
            <el-table-column prop="content" label="评论内容" />
            <el-table-column prop="createTime" label="时间" />
            <el-table-column prop="movieImg" label="电影海报">
                <template #default="{ row }">
                    <el-button type="danger" text @click="delCom(row)">删除</el-button>

                </template>
            </el-table-column>
        </CustomTable>
    </div>
</template>

<script setup lang="ts">
import CustomTable from '@/components/CustomTable.vue'
import { onMounted, reactive, ref } from 'vue'
import {
    getComments, delComments
} from '@/apis/movie'
import { ElMessage } from 'element-plus'
const tableData = ref([])
const tableTotal = ref(0)
const pageSize = ref(10)
const pageNum = ref(1)

const getList = async () => {
    const res = await getComments({
        pageNum: pageNum.value,
        pageSize: pageSize.value
    })
    tableData.value = res.list
    tableTotal.value = res.total
}
const delCom = async (row) => {
    await delComments(row.id)
    ElMessage.success("删除成功")
    getList()
}
onMounted(() => {
    getList()
})
</script>

<style scoped></style>
